package cn.auto.utility;

import com.jfinal.plugin.redis.Redis;
import redis.clients.jedis.Jedis;

public class RedisKit {
	
	public void pubMesage(String channel,String message) {
		Jedis jds = null;
		try{
			jds=Redis.use().getJedis();
			jds.publish(channel, message);
			System.out.println("测试任务队列id："+message+" 发布成功！");
		}catch (Exception e) {
			System.out.println("测试任务消息发布失败:"+e);
		}finally {
			jds.close();
		}
	}
	
	/**
	 * 添加队列元素
	 * @param queName   队列名称
	 * @param el      加入的元素
	 * @return
	 */
	public boolean addQueueEle(String queName,String el) {
		Jedis jds = null;
		boolean isCreate = true;
		try{
			jds=Redis.use().getJedis();
			jds.rpush(queName, el);
			System.out.println("脚本："+el+" 插入队列 "+queName+" 成功！");
		}catch (Exception e) {
			isCreate = false;
			System.out.println("脚本名加入测试任务队列 "+queName+" 失败！");
		}finally {
			jds.close();
		}
		return isCreate;
	}
	
	public Long getQueueLen(String queueName) {
		Jedis jds=Redis.use().getJedis();
		return jds.llen(queueName);
	}
}
